﻿#ifndef __CLIST_H__
#define __CLIST_H__

#ifdef __cplusplus
extern "C" {
#endif

#define NODE_DATA_PTR(node_ptr) ((char*)node_ptr + sizeof(void*) * 2) //sizeof(void*) -> sizeof(XLIST_NODE)
#define IT_PTR(it, usr_type) ((usr_type*)NODE_DATA_PTR(it.ptr))

typedef struct _xlist_itorator {
	//attribute
	void* ptr;

	//action
	void* (*next)(struct _xlist_itorator* thes);
} XListIterator;

typedef struct _xlist_ {
	//attribute
	void* ptr;
	int item_size;
	int cnt;

	//action
	int(*insert)(struct _xlist_* thes, void* e);
	int(*erase)(struct _xlist_* thes, XListIterator* it);
	void*(*begin)(struct _xlist_* thes);
	void*(*end)(struct _xlist_* thes);
	int(*release)(struct _xlist_* thes);
} XList;

int construct_xlist(XList* thes, int item_size);
int construct_clist_iterator(XListIterator* thes);

#ifdef __cplusplus
}
#endif
#endif
